const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  transpileDependencies: true,
  
  // 开发服务器配置
  devServer: {
    port: 8080,
    open: true,
    host: '0.0.0.0',
    https: false,
    proxy: {
      // API请求代理
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      },
      // 阿里云OSS图片代理 - 解决跨域问题
      '/aliyun-oss': {
        target: 'https://shuya-aiqc-hub.oss-cn-beijing.aliyuncs.com',
        changeOrigin: true,
        pathRewrite: {
          '^/aliyun-oss': ''
        }
      }
    }
  },
  
  // 构建配置
  configureWebpack: {
    resolve: {
      alias: {
        '@': require('path').resolve(__dirname, 'src')
      }
    }
  },
  
  // CSS配置
  css: {
    loaderOptions: {
      scss: {
        additionalData: `
          @import "@/styles/variables.scss";
        `
      }
    }
  },
  
  // 输出配置
  outputDir: 'dist',
  assetsDir: 'static',
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  
  // 生产环境配置
  productionSourceMap: false,
  
  // 链式配置
  chainWebpack: config => {
    // 设置标题
    config
      .plugin('html')
      .tap(args => {
        args[0].title = '云狐AI - 智能AI助手'
        return args
      })
    
    // 优化图片
    config.module
      .rule('images')
      .use('url-loader')
      .loader('url-loader')
      .tap(options => Object.assign(options, { limit: 10240 }))
  }
})
